package mo.offer_special;

public class L072 {

    public int mySqrt(int x) {
        if (x <= 1) {
            return x;
        }
        int left = 0;
        int right = x;
        while (left < right) {
            long mid = left + ((right-left) >> 1);
            long i = mid * mid;
            if (i == x) {
                return (int) mid;
            } else if (i < x) {
                left = (int) mid + 1;
            } else {
                right = (int) mid;
            }
        }
        return left - 1;
    }

    public static void main(String[] args) {
        L072 test = new L072();
        System.out.println(test.mySqrt(3));
    }

}
